home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / PlayerPRO 4.5.1 / MADH Library 4.01 / Game.c < prev    next >
C/C++ Source or Header  |  1996-02-07  |  3KB  |  138 lines

  1. /********************************************************/
  2. /*
  3.     Player PRO 4.5 -- Music Driver EXAMPLE
  4.  
  5.     Library Version 4.0
  6.  
  7.     To use with MusicLibrary 4.0 for Think C & CodeWarrior
  8.  
  9.     Antoine ROSSET
  10.     16 Tranchees
  11.     1206 GENEVA
  12.     SWITZERLAND
  13.     
  14.     FAX: (41 22) 346 11 97
  15.     Compuserve: 100277,164
  16.     Internet: rosset@dial.eunet.ch
  17. */
  18. /********************************************************/
  19.  
  20. #include "RDriver.h"
  21.  
  22. /*****************************/
  23. /****** MAIN FUNCTION ********/
  24. /*****************************/
  25.  
  26. void main( void)
  27. {
  28. OSErr            iErr;
  29. DialogPtr        TheDia;
  30. Handle            itemHandle;
  31. Rect            itemRect;
  32. short            itemType, i, itemHit;
  33. Handle            mySound[ 4];            // my 4 sound resource
  34.  
  35. /* Initialisation de la toolbox */
  36.  
  37. InitGraf( &qd.thePort);
  38. InitFonts();
  39. InitWindows();
  40. TEInit();
  41. InitMenus();
  42. InitCursor();
  43. MaxApplZone();
  44.  
  45. /******************************************/
  46. /*** Load and prepare my sound resource ***/
  47. /******************************************/
  48.  
  49. for( i = 0 ; i < 4; i++)
  50. {
  51.     mySound[ i] = GetResource( 'snd ', 128 + i);
  52.     DetachResource( mySound[ i]);
  53.     HLock( mySound[ i]);                            // VERY IMPORTANT !!!!!!
  54. }
  55.  
  56.  
  57. /*******************************************************************************************/
  58. /****** MAD Library Initialisation : choose the best driver for the current hardware ******/
  59. /******                                                                                  ******/
  60. /****** Standard initialization with 4 tracks...                                      ******/
  61. /*******************************************************************************************/
  62.  
  63. {
  64. MADDriverSettings    init;
  65.  
  66. init.numChn                = 4;
  67. init.outPutBits         = 8;
  68. init.outPutRate            = rate22khz;
  69. init.outPutMode            = StereoOutPut;
  70. init.driverMode            = SoundManagerDriver;
  71. init.antiAliasing        = false;
  72. init.repeatMusic        = false;
  73. init.sysMemory            = false;
  74. init.Interpolation        = false;
  75. init.MicroDelay            = false;
  76. init.MicroDelaySize     = 0;
  77. init.surround             = false;
  78.  
  79. MADInitLibrary("\p");
  80. if( MADCreateDriver( &init) != noErr) Debugger();
  81. }
  82.  
  83. if( MADLoadMusicRsrc( 'MADH', 3214) != noErr) Debugger();
  84. if( MADPlay() != noErr) Debugger();
  85.  
  86. /******************************************/
  87. /***        Open my dialog              ***/
  88. /******************************************/
  89.  
  90. TheDia = GetNewDialog( 128,0L, (WindowPtr) -1L);
  91. SetPort( TheDia);        
  92.  
  93. do
  94. {
  95.     ModalDialog( 0L, &itemHit);
  96.         
  97.     switch( itemHit)
  98.     {
  99.         case 2:
  100.             MADDriver->Reading = !MADDriver->Reading;
  101.             GetDItem( TheDia, 2, &itemType, &itemHandle, &itemRect);
  102.             SetCtlValue( (ControlHandle) itemHandle, !GetCtlValue( (ControlHandle) itemHandle));
  103.         break;
  104.     
  105.         case 3:
  106.             MADPlaySndHandle( mySound[ 0], 0, 48);            // On track ID 0, C 3 = 48
  107.         break;
  108.         
  109.         case 4:
  110.             MADPlaySndHandle( mySound[ 1], 1, 0xFF);        // On track ID 0, 0xFF = normal rate
  111.         break;
  112.         
  113.         case 5:
  114.             MADPlaySndHandle( mySound[ 2], 2, 36);            // On track ID 1, at C 2 = 36
  115.         break;
  116.         
  117.         case 6:
  118.             MADPlaySndHandle( mySound[ 3], 3, 60);            // On track ID 2, at C 4 = 60
  119.         break;
  120.     }
  121.     
  122. }while( itemHit != 1);
  123.  
  124. DisposDialog( TheDia);
  125.  
  126. MADStop();                            // Stop the driver
  127. MADDisposeMusic();                    // Clear music
  128. MADDisposeDriver();                    // Dispose driver
  129. MADDisposeLibrary();                // Close Music Library
  130.  
  131. for( i = 0 ; i < 4; i++)
  132. {
  133.     HUnlock( mySound[ i]);
  134.     DisposeHandle( mySound[ i]);
  135. }
  136. }
  137.  
  138.